package de.tuhrig.sportlog.user.log;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class LogWeather {

	private static final Logger logger = Logger.getLogger(LogWeather.class.getName());

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	@Persistent
	private double temperature;
	
	@Persistent
	private Condition condition;
	
	public enum Condition {
		
		chance_of_rain,
		sunny,
		mostly_sunny,
		partly_cloudy,
		mostly_cloudy,
		chance_of_storm,
		showers,
		rain,
		chance_of_snow,
		cloudy,
		mist,
		storm,
		thunderstorm,
		chance_of_tstorm,
		sleet,
		snow,
		icy,
		dust,
		fog,
		smoke,
		haze,
		flurries
	}
	
	public void setTemperature(double temperature) {
		this.temperature = temperature;
	}

	public double getTemperature() {
		return temperature;
	}

	public void setCondition(Condition condition) {
		this.condition = condition;
	}

	public Condition getCondition() {
		return condition;
	}

	public static Condition parseCondition(String condition) {

		logger.log(Level.INFO, "parseCondition with '" + condition + "'");
		
		for(Condition c: Condition.values()) {

			if(condition.contains(c.toString()))
				return c;
		}
		
		return null;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public Key getKey() {
		return key;
	}
	
	public String toString() {
		
		return
			"[LogWeather: temperature = '" + this.temperature + "' condition = '" + this.condition + "']";
	}
}